package com.gientech.consulconsumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URL;
import java.util.List;

/**
 * Created by bruce on 2022/11/17.
 */
@RestController
public class ConsumerController {
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/consume")
    public String consume(){
        String str = restTemplate.getForObject("http://localhost:8001/produce",String.class);
//        List<ServiceInstance> instances = this.discoveryClient.getInstances("provider");
//        ServiceInstance instance = instances.get(0);
//        URI uri = instance.getUri();
//        String targeturl = uri + "/produce";
//        String str = restTemplate.getForObject(targeturl,String.class);
        return str;
    }
}
